import request from '@/utils/request'
const baseUrl = "users";
// 用户登录
const login = (data) => {
    return request({
        url: `${baseUrl}/login`,
        method: 'post',
        data
    })
}

// 用户注册
const register = (data) => {
    return request({
        url:`${baseUrl}/register`,
        method: 'post',
        data
    })
}

// 获取用户信息
const getInfo = () => {
    return request({
        url: `${baseUrl}/info`,
        method: 'get'
    })
}


// 退出登录
const logout = () => {
    return request({
        url: `${baseUrl}/logout`,
        method: 'put'
    })
}

// 获取用户列表
const getUserList = (params) => {
    return request({
        url: `${baseUrl}/list`,
        method: 'get',
        params
    })
}

// 删除用户
const deleteUser = (id) => {
    return request({
        url: `${baseUrl}/${id}`,
        method: 'delete'
    })
}

// 审批用户
const approvalUser = (userId) => {
    return request({
        url: `${baseUrl}/approval/${userId}`,
        method: 'put'
    })
}

// 修改用户状态（启用或禁用）
const updateStatus = (status, userId) => {
    return request({
        url: `${baseUrl}/updateStatus/${status}/${userId}`,
        method: 'put'
    })
}

// 更新用户信息
const updateUser = (id, data) => {
    return request({
        url: `${baseUrl}/${id}`,
        method: 'put',
        data
    })
}

// 获取用户详情
const getUserDetail = (id) => {
    return request({
        url: `${baseUrl}/${id}`,
        method: 'get'
    })
}

// 重置用户密码
const resetPassword = (id) => {
    return request({
        url: `${baseUrl}/resetPassword/${id}`,
        method: 'put'
    })
}

// 获取所有学生信息
export const getStudents = (query) => {
    return request({
        url: `${baseUrl}/students/list`,
        method: 'get',
        params: query
    })
}

// 更新密码
export const updatePassword = (data) => {
    return request({
        url: `${baseUrl}/updatePassword`,
        method: 'put',
        data
    })
}

// 更新用户信息
export const updateUserInfo = (data) => {
    return request({
        url: `${baseUrl}/updateInfo`,
        method: 'put',
        data
    })
}

export default {
    login,
    register,
    getInfo,
    logout,
    getUserList,
    deleteUser,
    approvalUser,
    updateStatus,
    updateUser,
    getUserDetail,
    resetPassword,
    updatePassword,
    updateUserInfo
}